#!/usr/bin/env python
# coding: utf-8

import xml.dom.minidom
from xml.dom.minidom import Node

class tnxxx_ne_info_parse(object):
    def __init__(self,xmlfile):
        self.doc = xml.dom.minidom.parse(xmlfile)
    
    def get_nes_info(self):
        self.nes_info = {}
        
        nes_nodes=self.doc.getElementsByTagName("nes-info")[0]
        
        for ne_node in nes_nodes.getElementsByTagName("ne"):
            ne_info = {}
            ne_info["id"]       = ne_node.getAttribute("id")
            ne_info["ip"]       = ne_node.getAttribute("shelfip")
            ne_info["type"]     = ne_node.getAttribute('type')
            
            #增加单板信息
            chss_dict = {}
            chss_info = ne_node.getElementsByTagName("chss-info")[0]
            for chss in chss_info.getElementsByTagName("chss"):
                chss_id = chss.getAttribute("id")
                chss_dict[chss_id]          = {}
                chss_dict[chss_id]["id"]    = chss_id    
                chss_dict[chss_id]["type"]  = chss.getAttribute("type")
                chss_dict[chss_id]["slot"]  = chss.getAttribute("slot")
            
            ne_info["chss"]     = chss_dict
            self.nes_info[ne_info["id"]] = ne_info
            
        return self.nes_info
        
if __name__ == "__main__" :
    xml=tnxxx_ne_info_parse("D:\\HeavySmoker\\workspace\\suites\\suite_tn7x5\\tn7x5.xml")
    nes = xml.get_nes_info()
    